test(webhooks): hoist delivery route mocks#368
Conversation
Greptile SummaryThis PR fixes a Vitest temporal dead zone (TDZ) failure in the webhook deliveries route test by wrapping the top-level mock function declarations with
Confidence Score: 5/5Safe to merge — the change is a two-line test infrastructure fix with no impact on production code. The route implementation is untouched; only mock initialization in the test file changed. The vi.hoisted() pattern is the correct Vitest-recommended fix for this exact class of problem, and the four pagination tests now run with the same assertions as before. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Vitest as Vitest Runner
participant Hoist as vi.hoisted()
participant Mock as vi.mock()
participant Test as Test Suite
Note over Vitest: Module load / hoist phase
Vitest->>Hoist: "Execute vi.hoisted(() => ({ mockFrom, mockGetAuthContext }))"
Hoist-->>Vitest: mockFrom, mockGetAuthContext initialised
Vitest->>Mock: "Execute vi.mock("@/lib/auth/get-user", factory)"
Note over Mock: Factory safely references mockGetAuthContext (no TDZ)
Mock-->>Vitest: Module stubbed
Note over Vitest: Test execution phase
Vitest->>Test: beforeEach — mockGetAuthContext.mockResolvedValue(...)
Test->>Test: GET() called with NextRequest
Test->>Mock: getAuthContext() returns user and supabase with mockFrom
Test->>Test: supabase.from("webhooks").select.eq.single returns webhook data
Test->>Test: supabase.from("webhook_deliveries")...range returns deliveries and count
Test-->>Vitest: Assertions on res.status, range args, json.pagination
Reviews (1): Last reviewed commit: "test(webhooks): hoist delivery route moc..." | Re-trigger Greptile |
Summary
vi.hoisted()Paid task
https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e
Verification
pnpm exec vitest run 'src/app/api/webhooks/[id]/deliveries/route.test.ts'pnpm exec eslint 'src/app/api/webhooks/[id]/deliveries/route.test.ts'git diff --check